package gold.contest;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC5629 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public String reformatNumber(String number) {
            String formatNumber = number.replaceAll(" ", "").replaceAll("-", "");
            int pos = 0;
            StringBuilder sb = new StringBuilder();
            while (pos < formatNumber.length()) {
                if (pos + 4 < formatNumber.length()) {
                    sb.append(formatNumber.substring(pos, pos + 3)).append("-");
                    pos += 3;
                } else {
                    switch (formatNumber.length() - pos) {
                        case 2:
                        case 3:
                            sb.append(formatNumber.substring(pos, formatNumber.length()));
                            break;
                        case 4:
                            sb.append(formatNumber.substring(pos, pos + 2)).append("-").append(formatNumber.substring(pos + 2, pos + 4));
                            break;
                    }

                    break;
                }
            }

            return sb.toString();
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.reformatNumber("--17-5 229 35-39475 "));
    }

    public static void main(String[] args) throws Exception {
        LC5629 an = new LC5629();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
